<?php
/**
小区公告
 */
namespace App\Http\Controllers\Property;

use App\Common\json;
use App\Http\Controllers\Controller;
use App\Libraries\upload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CommunitybulletinController extends Controller{

    public function SelectCommunitybulletin(Request $request){
        if($request ->isMethod('post')) {
                $village_id     = $request ->input('village_id');
                $data = DB::table('notice')
                   // ->selecct('notice_id','notice_title')
                       ->where('notice_village',$village_id)
                       ->orderby('notice_create_time','ase')
                    ->get();
                foreach ($data as $value){
                    $notice_title    = $value ->notice_title;
                    $notice_id       = $value ->notice_id;
                    $notice_content  = $value ->notice_content;
                    $time            = $value ->notice_create_time;
                    $notice_type     = $value ->notice_type;
                    $da[]   = array('notice_title'=> $notice_title,'notice_id' =>$notice_id,'notice_type'=>$notice_type,
                        'notice_content'=>$notice_content,'time'=>$time);
                }
                if($data == true){
                    return json::json('success', '获取全部小区公告信息成功', $da);
                }else{
                    return json::json('failure', '由于网络或者不正当原因失败', json::value(2));
                }
        }
    }
    public function Communitybulletin(Request $request){
        if($request ->isMethod('post')){
            $notice_id    = $request ->input('notice_id');
            $data     = DB::table('notice')
                      ->where('notice_id',$notice_id)
                      ->get();
            foreach ($data as $value){
                $notice_title      = $value ->notice_title;
                $notice_content    = $value ->notice_content;
                if(empty($value ->notice_image)){
                    $notice_image  = [];
                }else{
                    $notice_image      = explode(',',$value ->notice_image);
                }

                $notice_create_time = $value ->notice_create_time;
                $da = array('notice_title' => $notice_title,'notice_content'=>$notice_content,'image'=>$notice_image,
                            'notice_create_time'=>$notice_create_time);
            }
            if($data == true){
                return json::json('success', '获取公告信息成功', $da);
            }else{
                $arr  = (object)array();
                return json::json('failure', '由于网络或者不正当原因失败',$arr);
            }
        }
    }

}